﻿<%
'以下定义一个显示表格的函数Query_List_GetSQL(),
'DISPFILD,要显示的字段, 如: name<姓名,department<部门,units<单位
'SQL,查询SQL语句,		如: select id,tel from aa 注：SQL语句的第一个字段必须为表或视图的关键字段
'PAGESIZE,每页显示数量,	如: 10
'HV,显示的方向,			如: "H"--横向显示,"V"--纵向显示

'delURL,删除数据的链接	如: XXX_delete.asp
'editURL,修改数据的链接	如: XXX_edit.asp
'detailURL,显示数据明细的链接	如: XXX_detail.asp
'detailURLsn,在第几个字段上显示detailURL，该值>=1，默认为1。


'如显示成功,返回值为真,不成功,返回值为假.
'多个字段间用,共分隔
'查询字段一定要包含在显示字段中.
'如字段名与要显示的名称不一样,用<共分隔,前面是字段名,后面是显示的名字,
'要进行搜索的字段,则一定要用<共分隔要字段名和显示字符

' 表名变量Table 请在此函数外赋值

' editURL_target="_blank", detailURL_target="_blank"
' editURL_target, detailURL_target 的值,在本函数外的调用页面中定义并赋值。其值为两个： ""和"_blank"。
' ""表示在本窗口打开(默认值),"_blank"表示在新窗口打开。只有需要在新窗口打开时,才需要定义并赋值为"_blank"。


'以下定义一个显示表格的函数Query_List_GetSQL(),
'DISPFILD,要显示的字段, 如: name<姓名,department<部门,units<单位
'SQL,查询SQL语句,		如: select id,tel from aa 注：SQL语句的第一个字段必须为表或视图的关键字段
'PAGESIZE,每页显示数量,	如: 10
'HV,显示的方向,			如: "H"--横向显示,"V"--纵向显示

'delURL,删除数据的链接	如: XXX_delete.asp
'editURL,修改数据的链接	如: XXX_edit.asp
'detailURL,显示数据明细的链接	如: XXX_detail.asp
'detailURLsn,在第几个字段上显示detailURL，该值>=1，默认为1。


'如显示成功,返回值为真,不成功,返回值为假.
'多个字段间用,共分隔
'查询字段一定要包含在显示字段中.
'如字段名与要显示的名称不一样,用<共分隔,前面是字段名,后面是显示的名字,
'要进行搜索的字段,则一定要用<共分隔要字段名和显示字符

' 表名变量Table 请在此函数外赋值

' editURL_target="_blank", detailURL_target="_blank"
' editURL_target, detailURL_target 的值,在本函数外的调用页面中定义并赋值。其值为两个： ""和"_blank"。
' ""表示在本窗口打开(默认值),"_blank"表示在新窗口打开。只有需要在新窗口打开时,才需要定义并赋值为"_blank"。

FUNCTION Query_List_GetSQL(DISPFILD,SQL,PAGESIZE,HV,delURL,editURL,detailURL,detailURLsn)
	'On Error Resume Next
	if detailURLsn="" or detailURLsn<1 then detailURLsn=1
	IF DISPFILD="" THEN DISPFILD="*"
	IF PAGESIZE="" THEN PAGESIZE=10
	DISPFILD1=DISPFILD&","

	dim fild(35),dispfil(35),dispfildlr
	dispfildlr=""
	i=1
	dispfild1=dispfild1
	do while instr(dispfild1,",")<>0
	star=instr(dispfild1,",")
	fild(i)=left(dispfild1,star-1)
	dispfil(i)=fild(i)
	if instr(fild(i),"<")<>0 then
	  fildbak=fild(i)
	  fild(i)=left(fildbak,instr(fildbak,"<")-1)
	  dispfil(i)=right(fildbak,len(fildbak)-instr(fildbak,"<"))
	end if
	dispfildlr=dispfildlr&fild(i)&","
	dispfild1=right(dispfild1,len(dispfild1)-star)
	i=i+1
	loop
	dispfildlr=left(dispfildlr,len(dispfildlr)-1)
	if SQL="" then 
	   Query_List_GetSQL=True
	   exit function 'response.end
	end if
	'response.write sql&"<br>"
	rs.Open sql,conn,1,1


	if PageNo<=0 or PageNo="" then PageNo=1
	'  if not rs.eof and SQL<>"" then
	if not rs.eof then
	  rs.pagesize=PAGESIZE
	  pagezs=rs.pagecount
	IF cint(PageNo)>pagezs THEN PageNo=PAGEZS
	   zs=rs.recordcount
	   page=(PageNo-1)*PAGESIZE   
	   rs.move page,1 

	   IF HV="H" THEN '横向
		 Response.Write  " <table border='0' width='100%' cellspacing='1' cellpadding='0'>"&CR
		 Response.Write  " <tr bgcolor='#99CCFF' align='center' height=24 class=tbtop> "&CR '#EDBAA5
		 Response.Write "<TD width=35 align=center>序号</TD>"&CR
		 for ii=1 to i-1
		   Response.Write  "<td>"&dispFIL(ii)&"</td>"&CR
		 Next

		'显示其他操作标题
		If Other_Title<>"" Then 
			Other_Title_Array = Split(Other_Title,"#")
			For x=0 To UBound(Other_Title_Array)
				width=Len(Other_Title_Array(X))*13

				Response.Write "<TD width="&width&">"&Other_Title_Array(x)&"</TD>"&CR

			Next 
		End If 

		 if editURL<>"" then
			 Response.Write "<TD width=26 align=center>编辑</TD>"&CR
		 end If
		 
		 Response.Write "<TD width=35 align=center>选择</TD>"&CR

		 Response.Write  "</tr>"&CR
		 for iii=1 to PAGESIZE
		   No=(PageNo-1)*PAGESIZE + iii '序号
		   Response.Write "<tr bgcolor='#F0F0F0' height=21 style='cursor:hand' OnMouseOut=""this.style.backgroundColor='#F0F0F0'"" OnMouseOver=""this.style.backgroundColor='#cccccc'"">"&CR '#FFFAEE 
		   Response.Write "<TD width=35 align=center><font size=2>" & No & "</font></TD>"&CR

		   FOR II=1 TO I-1 '列
			if II=detailURLsn and detailURL<>"" then '明细
				if Instr(detailURL,"?")=0 then
				Response.Write "<td align=center><FONT SIZE='2'><a href='"&detailURL&"?"&rs.Fields(0).Name&"="&rs(0)&"' target='"&detailURL_target&"'>"&trim(RS(fild(II)))&"</a></FONT></td>" &CR
				else
				Response.Write "<td align=center><FONT SIZE='2'><a href='"&detailURL&"&"&rs.Fields(0).Name&"="&rs(0)&"' target='"&detailURL_target&"'>"&trim(RS(fild(II)))&"</a></FONT></td>"&CR 
				end if
			else
			   Response.Write "<td align=center><FONT SIZE='2'>"&trim(RS(fild(II)))&"</FONT></td>"&CR 
			end if
		   Next
		   
			If Other_Url<>"" Then 
				Other_Url_Array = Split(Other_Url,"#")
				For x=0 To UBound(Other_Url_Array)

					'writebr Other_Url_Array(x)


					Response.Write "<TD align=center>"&CR
					URL = Other_Url_Array(x)
					if Instr(URL,"?")=0 Then
						Response.Write "<a href='"&URL&"?"&rs.Fields(0).Name&"="&rs(0)&"' ><img src='/2010admin/images/edit.gif' border='0'></a>"&CR 
					else
						Response.Write "<a href='"&URL&"&"&rs.Fields(0).Name&"="&rs(0)&"' ><img src='/2010admin/images/edit.gif' border='0'></a>"&CR 
					end if
					Response.Write "</TD>"&CR


				Next 
			End If 

		   if editURL<>"" Then
				Response.Write "<td width=35 align=center>"&CR
				if Instr(editURL,"?")=0 then
					Response.Write "<a href='"&editURL&"?"&rs.Fields(0).Name&"="&rs(0)&"' target='"&editURL_target&"'><img src='/2010admin/images/edit.gif' border='0'></a></td>"&CR '编辑
				else
					Response.Write "<a href='"&editURL&"&"&rs.Fields(0).Name&"="&rs(0)&"' target='"&editURL_target&"'><img src='/2010admin/images/edit.gif' border='0'></a>"&CR '编辑
				end If
				Response.Write "</td>"&CR
		   end If
		   



		   '选择框
		   Response.Write "<td width=35 align=center><input type=""checkbox"" name=""Op_ID"" id=""Op_ID""  value="""&rs(0)&"""></td>"&CR '删除

		   
			Response.Write "</tr>"&CR

		  RS.MOVENEXT
		  if rs.eof then exit for
		next
		Response.Write "</table>"&CR

	ELSE	'纵向
	   Response.Write  " <table border='0' width='100%' cellspacing='1' cellpadding='0'>"&CR
	   for iii=1 to PAGESIZE
		   No=(PageNo-1)*PAGESIZE + iii '序号
		   Response.Write "<tr height=20><td bgcolor='#99ccff' ALIGN='RIGHT' WIDTH='20%'>序号：</td><td bgcolor='#99ccff' style='cursor:hand' OnMouseOut=""this.style.backgroundColor='#F0F0F0'"" OnMouseOver=""this.style.backgroundColor='#cccccc'"">"&No&"</td></tr>"&CR '#EDBAA5  #FFFAEE

		   FOR II=1 TO I-1
			 Response.Write "<tr height=20><td bgcolor='#f0f0f0' ALIGN='RIGHT' WIDTH='20%'>"&dispFIL(ii)&"：</td><td bgcolor='#F0F0F0' style='cursor:hand' OnMouseOut=""this.style.backgroundColor='#F0F0F0'"" OnMouseOver=""this.style.backgroundColor='#cccccc'"">"&trim(RS(fild(II)))&"</td></tr>"&CR '#EDBAA5  #FFFAEE #99ccff
		   NEXT
		   Response.Write "<tr height='4'><td bgcolor='#ffffff' colspan='2' ALIGN='RIGHT' WIDTH='20%'> </td></tr>"&CR '#CFBA9E
		RS.MOVENEXT
		if rs.eof then exit for
	  next
	  Response.Write "</table>"&CR
	END IF

	Response.Write  "<table  bgcolor='#99CCFF' border='0' width='100%'>"&CR
	if zs>=11 and TOPSN<>"" then
	  Response.Write  "<tr ><td width='25%'>记录总数太多，仅显示前面<B>"&ZS&"</B>条；共分<B>"&PAGEZS&"</B>页，现在是第<FONT COLOR=#ff0000>"&PageNo&"</FONT>页"&CR
	else
	  Response.Write  "<tr><td width='25%'>总共<B>"&ZS&"</B>条记录，共分<B>"&PAGEZS&"</B>页，现在是第<FONT COLOR=#ff0000>"&PageNo&"</FONT>页"&CR
	end If
	Response.Write "</td>"&CR
	Response.Write  "<td width='5%' align='center'><input type='submit' class=inputbutton name='previous' value='上一页'>&nbsp;&nbsp;<input type='submit' class=inputbutton name='next' value='下一页'></td>"&CR
	Response.Write  "<td width='20%' align='left'>"&CR
	Response.Write  "&nbsp;&nbsp;跳转到第"&CR
	Response.Write  "<input type='text' name='GotoPageNo2' size='2'>页&nbsp;<input type='submit' class='inputbutton' value='确定' name='B1'>&nbsp;&nbsp;"&CR
	Response.Write  "</td>"&CR
	Response.Write  "<td width='50%' ALIGN='RIGHT'>"&CR
	Response.Write  "全选<input type=""checkbox"" name=""Select_All"" id=""Select_All"" onClick=""checkall();""  >&nbsp;&nbsp;"&CR
	Response.Write "<input type='button' class='inputbutton' value='删除所选' name='B1' onClick=""return batch_del();"">"&CR
	Response.Write "<input type='hidden' name='op_action' value='del'  >"&CR
	Response.Write "<input type='hidden' name='del_action' value='"&delURL&"'  >"&CR

	'设置置顶
	If Sort_Name<>"" Then 
		Response.Write  "&nbsp;&nbsp;置顶到："
		Selected_BySql "Sort_Type","SELECT Sort_Sub_ID,Sort_Sub_Name FROM uvw_Sort_Type WHERE Sort_Name='"&Sort_Name&"'ORDER BY Sort_Sub_Order ASC","",Sort_Type
		Response.Write "<input type='button' class='inputbutton' value='确定' name='B1' onClick=""return Set_Sort();"">"
		Response.Write "<input type='hidden' class='inputbutton' value='"&Set_Top_URL&"' name='Sort_Action' id='Sort_Action' >"
		
	End If 


	Response.Write  "</td>"&CR
	Response.Write  "</tr>"&CR
	Response.Write  "</table> "&CR

	rs.close
	else
	rs.close
	Response.Write "<br><center><font size=2 color=#0000ff>没有找到符合条件的记录!</font></center>"&CR
	end if
	response.write "<input type='hidden' name='PageNo' value='"&PageNo&"'>"&CR

	If Err.Number = 0 Then
	Query_List_GetSQL=True
	Else
	Err.Clear
	Query_List_GetSQL=False
	End If
END Function
%>
